/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentation;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.jdesktop.swingx.JXDatePicker;

/**
 *
 * @author Domenico
 */
class InputVerifierNotEmpty extends InputVerifier {
    private String nomeCampo;
    
    public InputVerifierNotEmpty(String campo) {
        nomeCampo = campo;
        
    }

    @Override
    public boolean verify(JComponent input) {
        boolean empty = false;
        if (input instanceof JTextField) {
            JTextField tf = (JTextField) input;
            empty = tf.getText().isEmpty();
        } else if (input instanceof JXDatePicker) {
            JXDatePicker tf = (JXDatePicker) input;
            empty = (tf.getDate() == null);
        }
        
        if (empty) {
            notificaErrore("Inserire: ", "Dato non inserito", input);
            
        }
        return !empty;
    }
   
    protected void notificaErrore(String messaggio, String titolo, JComponent input) {
        
        JOptionPane.showMessageDialog(input,
        messaggio + "'" + nomeCampo + "'",
        titolo, JOptionPane.WARNING_MESSAGE);
    }
}
